package com.yellow.orderservice.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yellow.orderservice.entity.Order;
import com.yellow.orderservice.entity.Sender;
import com.yellow.orderservice.mapper.SenderMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: hy
 * @create: 2024-04-16
 */
@Service
public class SenderServiceImpl extends ServiceImpl<SenderMapper, Sender> implements SenderService {
    @Resource
    private SenderMapper senderMapper;
    @Override
    public void insertSender(Sender sender) {
            senderMapper.insert(sender);
    }

    @Override
    public Long findIdByName(String name) {
        LambdaQueryWrapper<Sender> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Sender::getName, name);

        Sender sender = senderMapper.selectOne(wrapper);
        return sender.getSenderId();
    }

    @Override
    public List<Sender> findSenderByName(String name) {
        LambdaQueryWrapper<Sender> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Sender::getName, name);
        return senderMapper.selectList(wrapper);
    }

    @Override
    public List<Order> getOrdersBySenderName(String name) {
        return senderMapper.getOrdersBySenderName(name);
    }

    @Override
    public Long countSenders() {
        return senderMapper.selectCount(null);
    }


}
